var user_info = ""
var user_allwork = ""
var user_attent = ""
var user_fans = ""
var user_like = ""
var user_message = ""
var user_collect = ""
var user_comment = ""
var user_caogao = ""


$(function (message) {
    // window.localStorage.clear();
    if (user_data == "") {
        alert("请先登录");
        window.location.href = "login.html?type_to=" + "create";
        return
    }
    dirName = "ydupf/user/" + user_data.id;
    //调用连接
    getindex(user_data.id, "", 1, 100);
    getmessage(0, 1, 100)
    getcollect(1, 100)
    getcomment(1, 100);


    //页面样式
    let create_type = $_GET["type"] ? $_GET["type"] : "zhuye";
    //填写页面数据
    $("#user_allwork").text(user_info.worksTotal)
    $("#user_attent").text(user_info.followTotal)
    $("#user_fans").text(user_info.fansTotal)
    $("#user_like").text(user_info.likesTotal)
    if (user_allwork.data.length == 0) {
        $("#user_work_name").text("暂无作品")
    } else {
        $("#user_work_name").text(user_allwork.data[0].title)
        var userworkimg = getPicUrl(getAliossPath("work/" + user_allwork.data[0].id, user_allwork.data[0].tpic), 60, 0);
        $("#user_work_img").append(
            '<img src="' + userworkimg + '" style="max-width: 90px; max-height: 90px" alt="作品">'
        );
        $("#xiangqing_index").attr("type", user_allwork.data[0].id)
        $("#xiangqing_index").attr("type_type", user_allwork.data[0].type)

        $("#user_work_time").text(time(user_allwork.data[0].createdTime))
        $("#user_work_comm").text(user_allwork.data[0].commentCount)
        $("#user_work_like").text(user_allwork.data[0].likes)
    }


    let data_length = 4
    if (user_message.data != null) {
        if (user_message.data.length < 5) {
            data_length = user_message.data.length
        } else {
            data_length = 4
        }
        for (let i = 0; i < data_length; i++) {
            $("#user_message").append(
                '<li class="myModal_mess" text="' + user_message.data[i].content + '"><a><div class="xiaoxi_1"><span class="changdu"><span style="margin-right: 5px">' +
                time(user_message.data[i].createdTime) + '</span>' + user_message.data[i].content + '</span>'
                // '<span class="xin">新</span></div></a></li>'
            )
        }
        for (let i = 0; i < user_message.data.length; i++) {
            $("#user_allmessage").append(
                '<div class="xiaoxi_1  myModal_mess" text="' + user_message.data[i].content + '"><a><span class="changdu">' +
                user_message.data[i].content + '</span><span class="xin">' +
                time(user_message.data[i].createdTime) + '</span></a></div>'
            )
        }
    } else {
        $("#user_message").append(
            '<div> 暂无消息 </div>'
        )
    }


    //设置页面的数据
    $("#user_name").text(user_data.name);
    $("#user_account").text(user_data.username);
    var userimg = getPicUrl(getAliossPath("user/" + user_data.id, user_data.headimg), 300, 0);
    $("#user_headimg").attr("src", userimg);
    $(".img-circle").attr("src", userimg);
    $(".nicheng").text(user_data.name);
    $(".renzheng").text(authType(user_data.authType)).addClass(user_data.authType);
    if (user_data.signature == null) {
        $(".qianming").text("未设置")
    } else {
        $(".qianming").text(user_data.signature)
    }

    $(".mima input").val(user_data.password)
    if (user_data.sex == 1) {
        $("#user_sex2").hide()
    } else {
        $("#user_sex1").hide()
    }

    //24小时热闻方法
    $.ajax({
        url: baseURL + '/webapi/works/searchRecommend',
        type: 'post',
        dataType: 'json',
        headers: {'authorities': authorities},
        data: {
            prop: -1,
            rotation: -1,
            pageNum: 1,
            pageSize: 5,
        },
        // async: false,//同步
        success: function (data) {
            //for i 循环
            for (let i = 0; i < 5; i++) {
                let num = i + 1;
                $(".redian").append(
                    '<div class="redian_1" type="' + data.data[i].type + '" uid="' + data.data[i].id + '">' +
                    '<a>' +
                    '<span class="changdu">' +
                    '<span class="redian_sort sort_1">' + num + '</span>' +
                    data.data[i].title +
                    '</span>' +
                    '</a>' +
                    '</div>'
                );
            }
        }
    });
    //置顶的内容
    $.ajax({
        url: baseURL + '/webapi/works/searchRecommend',
        type: 'post',
        dataType: 'json',
        headers: {'authorities': authorities},
        data: {
            prop: -1,
            rotation: -1,
            pageNum: 1,
            pageSize: 5,
        },
        // async: false,//同步
        success: function (data) {
            let num = 1
            for (let i = 0; i < data.data.length; i++) {
                if (data.data[i].tpic != "" && data.data[i].tpic != null && data.data[i].type != "news") {
                    if (num == 1) {
                        let userworkimg = getPicUrl(getAliossPath("work/" + data.data[i].id, data.data[i].tpic), 240, 0);
                        $(".carousel-inner").append(
                            '<div class="item active" type="' + data.data[i].type + '" uid="' + data.data[i].id + '">' +
                            '<img src="' + userworkimg + '" alt="First slide">' +
                            '<div class="carousel-caption">' + data.data[i].title + '</div>' +
                            '</div>'
                        );
                    } else if (num == 4) {
                        return
                    } else {
                        let userworkimg = getPicUrl(getAliossPath("work/" + data.data[i].id, data.data[i].tpic), 240, 0);
                        $(".carousel-inner").append(
                            '<div class="item" type="' + data.data[i].type + '" uid="' + data.data[i].id + '">' +
                            '<img src="' + userworkimg + '" alt="Second slide">' +
                            '<div class="carousel-caption">' + data.data[i].title + '</div>' +
                            '</div>'
                        );
                    }
                    num++;
                }


            }
        }

    })


    switch (create_type) {
        case "zhuye":
            $(".zhuye").show().siblings().hide();
            break;
        case "shezhi":
            $(".shezhi").show().siblings().hide();
            break;
        case "zuopinguanli":
            //文章
            for (let i = 0; i < user_allwork.data.length; i++) {
                let data = user_allwork.data[i];
                var workimg = getPicUrl(getAliossPath("work/" + data.id, data.tpic), 190, 0);
                var headimg = getPicUrl(getAliossPath("user/" + data.updatedBy, data.headImg), 30, 0);
                if (data.tpic != null && data.tpic != "") {
                    $(".all-item").append(
                        '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                        '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                        '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                        '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                        '<img class="avatar" src="' + headimg + '">' +
                        data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                        time(data.createdTime) + '</span></p></div></div></div>'
                    )
                    // type 作品类型,微头条:headlines,文章:article,图文:imgtext,长视频:lvideo,短视频:svideo
                    switch (data.type) {
                        case "article":
                            $(".article-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                                '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                                '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "headlines":
                            $(".Headlines-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                                '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                                '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "imgtext":
                            $(".img-text-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                                '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                                '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "lvideo":
                            $(".video-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                                '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                                '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "svideo":
                            $(".micro-video-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div class="col-xs-3">' +
                                '<img class="post-object link" style="height: 120px" src="' + workimg + '"></div>' +
                                '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading link">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                    }
                } else {
                    //无图片的样式
                    $(".all-item").append(
                        '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                        '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                        '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                        '<img class="avatar" src="' + headimg + '">' +
                        data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                        time(data.createdTime) + '</span></p></div></div></div>'
                    )
                    // type 作品类型,微头条:headlines,文章:article,图文:imgtext,长视频:lvideo,短视频:svideo
                    switch (data.type) {
                        case "article":
                            $(".article-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                                '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "headlines":
                            $(".Headlines-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                                '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "imgtext":
                            $(".img-text-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                                '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "lvideo":
                            $(".video-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                                '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                        case "svideo":
                            $(".micro-video-item").append(
                                '<div class="post-list-item" userProp="'+data.userProp+'" type="' + data.id + '" type_type="' + data.type + '"><div style="height: 20px"></div>' +
                                '<div class="col-sm-9 link"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                                '<div class="post-heading">' + data.title + '</div></a><p class=""><span class="user_link" user_id="' + data.updatedBy + '">' +
                                '<img class="avatar" src="' + headimg + '">' +
                                data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                                time(data.createdTime) + '</span></p></div></div></div>'
                            )
                            break;
                    }

                }

                if (data.userProp == 1) {

                }

            }
            //收藏
            for (let i = 0; i < user_collect.data.length; i++) {
                let data2 = user_collect.data[i];
                if (data2.tpic != null && data2.tpic != "") {
                    if (data2.type == "news") {
                        let work_shoucangimg = getPicUrl(getAliossPath("work", data2.tpic), 300, 0);
                        let headimg = getPicUrl(getAliossPath("user/" + data2.updatedBy, data2.headImg), 30, 0);
                        $(".collection-item").append(
                            '<div class="post-list-item not_top" del_type="collect" type="' + data2.id + '" type_type="' + data2.type + '"><div class="col-xs-3">' +
                            '<img class="post-object link" style="height: 120px" src="' + work_shoucangimg + '"></div>' +
                            '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data2.title + '</div></a><p class=""><span>' +
                            // '<img class="avatar" src="' + headimg + '">' +
                            data2.author + '</span> ⋅<span>评论 ' + data2.commentCount + '</span> ⋅<span>点 赞' + data2.likes + '</span> ⋅<span>' +
                            time(data2.createdTime) + '</span></p></div></div></div>'
                        )
                    } else {
                        let work_shoucangimg = getPicUrl(getAliossPath("work/" + data2.id, data2.tpic), 300, 0);
                        let headimg = getPicUrl(getAliossPath("user/" + data2.updatedBy, data2.headImg), 30, 0);
                        $(".collection-item").append(
                            '<div class="post-list-item not_top" del_type="collect" type="' + data2.id + '" type_type="' + data2.type + '"><div class="col-xs-3">' +
                            '<img class="post-object link" style="height: 120px" src="' + work_shoucangimg + '"></div>' +
                            '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data2.title + '</div></a><p class=""><span class="user_link" user_id="' + data2.updatedBy + '">' +
                            '<img class="avatar" src="' + headimg + '">' +
                            data2.uname + '</span> ⋅<span>评论 ' + data2.commentCount + '</span> ⋅<span>点 赞' + data2.likes + '</span> ⋅<span>' +
                            time(data2.createdTime) + '</span></p></div></div></div>'
                        )
                    }
                } else {
                    if (data2.type == "news") {
                        let work_shoucangimg = getPicUrl(getAliossPath("work", data2.tpic), 190, 0);
                        let headimg = getPicUrl(getAliossPath("user/" + data2.updatedBy, data2.headImg), 30, 0);
                        $(".collection-item").append(
                            '<div class="post-list-item not_top" del_type="collect" type="' + data2.id + '" type_type="' + data2.type + '"><div></div>' +
                            '<div class="col-sm-9 "><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data2.title + '</div></a><p class=""><span>' +
                            // '<img class="avatar" src="' + headimg + '">' +
                            data2.author + '</span> ⋅<span>评论 ' + data2.commentCount + '</span> ⋅<span>点 赞' + data2.likes + '</span> ⋅<span>' +
                            time(data2.createdTime) + '</span></p></div></div></div>'
                        )
                    } else {
                        let work_shoucangimg = getPicUrl(getAliossPath("work/" + data2.id, data2.tpic), 190, 0);
                        let headimg = getPicUrl(getAliossPath("user/" + data2.updatedBy, data2.headImg), 30, 0);
                        $(".collection-item").append(
                            '<div class="post-list-item not_top" del_type="collect" type="' + data2.id + '" type_type="' + data2.type + '"><div class="col-xs-3">' +
                            '<img class="post-object link" style="height: 120px" src="' + work_shoucangimg + '"></div>' +
                            '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data2.title + '</div></a><p class=""><span class="user_link" user_id="' + data2.updatedBy + '">' +
                            '<img class="avatar" src="' + headimg + '">' +
                            data2.uname + '</span> ⋅<span>评论 ' + data2.commentCount + '</span> ⋅<span>点 赞' + data2.likes + '</span> ⋅<span>' +
                            time(data2.createdTime) + '</span></p></div></div></div>'
                        )
                    }


                }

            }

            //草稿箱
            // console.log(window.localStorage.getItem("caogao"))
            if (window.localStorage.getItem("caogao") != "" && window.localStorage.getItem("caogao") != null) {
                user_caogao = JSON.parse(window.localStorage.getItem("caogao"));
                for (let i = 0; i < user_caogao.length; i++) {
                    let data = user_caogao[i];
                    $(".caogaoxiang-item").append(
                        '<div class="post-list-item not_top" del_type="caogao" type="' + i + '" type_type="' + data.type_type + '"><div></div>' +
                        '<div class="col-sm-9 to_caogao"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                        '<div class="post-heading">' + data.title + '</div></a><p class=""><span>' +
                        data.type_type + '草稿</span></p></div></div></div>'
                    )
                }
            } else {
                user_caogao = []
            }
            console.log(user_caogao)


            $('#collapseTwo').collapse('show');
            $(".guanli").find(".jiantou").removeClass("glyphicon-menu-down");
            $(".guanli").find(".jiantou").addClass("glyphicon-menu-up");
            $(".Two_zuopin").addClass("but_color").siblings().removeClass("but_color");
            $(".zuopinguanli").show().siblings().hide();
            break;
        case "pinglunguanli":
            for (let i = 0; i < user_comment.data.length; i++) {
                let data = user_comment.data[i];
                var workimg2 = getPicUrl(getAliossPath("work/" + data.id, data.tpic), 190, 0);
                var headimg2 = getPicUrl(getAliossPath("user/" + data.updatedBy, data.headImg), 30, 0);
                if (data.tpic != null && data.tpic != "") {
                    if (data.type == "news") {
                        $("#pinglun_xiangqing").append(
                            '<div class="post-list-item pinglun" del_type="pinglun" type="' + data.id + '" type_type="' + data.type + '"> <div class="col-xs-3">' +
                            '<img class="post-object link" style="height: 120px" src="' + workimg2 + '"></div>' +
                            '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data.title + '</div></a><p class=""><span  class="user_link" user_id="' + data.updatedBy + '">' +
                            // '<img class="avatar" src="' + headimg2 + '">' +
                            data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                            time(data.createdTime) + '</span></p></div></div></div>'
                        )
                    } else {
                        $("#pinglun_xiangqing").append(
                            '<div class="post-list-item pinglun" del_type="pinglun" type="' + data.id + '" type_type="' + data.type + '"> <div class="col-xs-3">' +
                            '<img class="post-object link" style="height: 120px" src="' + workimg2 + '"></div>' +
                            '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data.title + '</div></a><p class=""><span  class="user_link" user_id="' + data.updatedBy + '">' +
                            '<img class="avatar" src="' + headimg2 + '">' +
                            data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                            time(data.createdTime) + '</span></p></div></div></div>'
                        )
                    }
                } else {
                    if (data.type == "news") {
                        $("#pinglun_xiangqing").append(
                            '<div class="post-list-item pinglun" del_type="pinglun" type="' + data.id + '" type_type="' + data.type + '"> <div></div>' +
                            '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data.title + '</div></a><p class=""><span  class="user_link" user_id="' + data.updatedBy + '">' +
                            // '<img class="avatar" src="' + headimg2 + '">' +
                            data.uname + '</span> ⋅<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅<span>' +
                            time(data.createdTime) + '</span></p></div></div></div>'
                        )
                    } else {
                        $("#pinglun_xiangqing").append(
                            '<div class="post-list-item pinglun" del_type="pinglun" type="' + data.id + '" type_type="' + data.type + '"> <div></div>' +
                            '<div class="col-sm-9"><div class="col-sm-12" style="margin-top: 5px"><a>' +
                            '<div class="post-heading link">' + data.title + '</div></a><p class=""><span  class="user_link" user_id="' + data.updatedBy + '">' +
                            '<img class="avatar" src="' + headimg2 + '">' + data.uname + '</span> ⋅' +
                            '<span>评论 ' + data.commentCount + '</span> ⋅<span>点赞 ' + data.likes + '</span> ⋅' +
                            '<span>' + time(data.createdTime) + '</span></p></div></div></div>'
                        )
                    }
                }
            }

            $('#collapseTwo').collapse('show');
            $(".guanli").find(".jiantou").removeClass("glyphicon-menu-down");
            $(".guanli").find(".jiantou").addClass("glyphicon-menu-up");
            $(".Two_pinglun").addClass("but_color").siblings().removeClass("but_color");
            $(".pinglunguanli").show().siblings().hide();
            break;


    }
    $("#collapseTwo .list-group-item").on("click", function () {
        let menu_type = $(this).attr("type");
        window.location.href = "create.html?type=" + menu_type;
    })


    // 滑过用户显示设置
    $(".mengban2").click(function () {
        let type1 = $(".demo").is(":visible")
        let type2 = $(".publish_menu").is(":visible")
        if (type1) {
            $(".demo").hide();
        } else if (type2) {
            $(".publish_menu_but").find(".jiantou").removeClass("glyphicon-triangle-top");
            $(".publish_menu_but").find(".jiantou").addClass("glyphicon-triangle-bottom");
            $(".publish_menu").hide();
        }
        $(".mengban2").hide();
    })
    $(".yonghu,.demo").click(function () {
        $(".mengban2").show();
        $(".demo").css("left", $(".yonghu").offset().left);
        $(".demo").toggle();
    })

    //点击菜单
    $(".panel-heading").on("click", function () {
        let text = $(this).find(".jiantou").attr("class");
        if (text) {
            if (text.lastIndexOf("glyphicon-menu-down") !== -1) {
                $(this).find(".jiantou").removeClass("glyphicon-menu-down");
                $(this).find(".jiantou").addClass("glyphicon-menu-up");
            } else {
                $(this).find(".jiantou").removeClass("glyphicon-menu-up");
                $(this).find(".jiantou").addClass("glyphicon-menu-down");
            }
        }

    })
    //点击搜索
    $("#search_btn").on("click", function () {
        let search_content = $(".form-control").val();
        $.session.set('search_content', search_content)
        //跳转
        window.open("search.html");
        // window.location.href = "search.html";
        // }


        // $.ajax({
        //     url: baseURL + '/webapi/works/searchAllWorksPage',
        //     type: 'post',
        //     dataType: 'json',
        //     headers: {'authorities': authorities},
        //     data: {
        //         wd: search_content,
        //         pageNum: 1,
        //         pageSize: 20,
        //     },
        //     async: false,//同步
        //     success: function (data) {
        //         let search_user = [], searchWork = data.data
        //         console.log(data);
        //         for (let i = 0; i < searchWork.length; i++) {
        //             if (searchWork[i].updatedBy == user_info.id) {
        //                 search_user = search_user.concat(searchWork[i])
        //             }
        //         }
        //         console.log(search_user)
        //     }
        // })
    })
    //点击切换页面
    $("#zhuye").on("click", function () {
        let menu_type = $(this).attr("type");
        window.location.href = "create.html?type=" + menu_type;

    })
    $("#shezhi").on("click", function () {
        let menu_type = $(this).attr("type");
        window.location.href = "create.html?type=" + menu_type;
    })
    $("#demo_shezhi").on("click", function () {
        let menu_type = $(this).attr("type");
        window.location.href = "create.html?type=" + menu_type;
    })
    $(".xiaoxi_but").on("click", function () {
        $(".gonggao_xiaoxi").show().siblings().hide();
    })
    $(".zuopin_but").on("click", function () {
        window.location.href = "create.html?type=" + "zuopinguanli";
    })

    //作品管理页面切换
    $(".tab-item").on("click", function () {
        $(".tab-item").removeClass("active");
        $(this).addClass("active");
        $(this).show();
    });
    $(".all").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".all-item").removeClass("hide");
    });
    $(".Headlines").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".Headlines-item").removeClass("hide");
    });
    $(".article").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".article-item").removeClass("hide");
    });
    $(".img-text").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".img-text-item").removeClass("hide");
    });
    $(".video").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".video-item").removeClass("hide");
    });
    $(".micro-video").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".micro-video-item").removeClass("hide");
    });
    $(".collection").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".collection-item").removeClass("hide");
    });
    $(".caogaoxiang").on("click", function () {
        $(".feed-list").addClass("hide");
        $(".caogaoxiang-item").removeClass("hide");
    });

    //删除/置顶，作品按钮
    $(".post-list-item").not(".pinglun").hover(function () {
        $(this).append(
            '<span class="glyphicon glyphicon-trash post_list_shanchu" aria-hidden="true" title="删除"></span>'
        );
    }, function () {
        $(".post_list_shanchu").remove();
    })
    $(".post-list-item").not(".pinglun,.not_top").hover(function () {
        let Prop = $(this).attr("userProp");
        if (Prop == 1){
            $(this).append(
                '<span class="glyphicon glyphicon-eject post_list_top" aria-hidden="true" title="取消置顶"></span>'
            );
        }else {
            $(this).append(
                '<span class="glyphicon glyphicon-eject post_list_top" aria-hidden="true" title="置顶"></span>'
            );
        }

    }, function () {
        $(".post_list_top").remove();
    })
    //删除
    $(".post-list-item").on("click", ".post_list_shanchu", function () {
        let _this = $(this)
        let wid = _this.parent(".post-list-item").attr("type")
        let del_type = _this.parent(".post-list-item").attr("del_type")
        if (del_type == "collect") {
            if (confirm('确定取消收藏吗') == true) {
                if (CollecWorks(wid) == '1') {
                    _this.parent().remove();
                }
            }
        } else if (del_type == "pinglun") {
            if (confirm('确定删除评论吗') == true) {
                if (del_pinglun(wid) == "1") {
                    _this.parent().remove();
                }

            }
        } else if (del_type == "caogao") {
            if (confirm('确定删除草稿吗') == true) {
                if (del_caogao(wid) == "1") {
                    _this.parent().remove();
                }

            }
        } else {
            if (confirm('确定要删除吗') == true) {
                if (remove_work(wid) == "1") {
                    _this.parent().remove();
                }
            }
        }

        // $(this).parent().remove();
    })
    //置顶
    $(".post-list-item").on("click", ".post_list_top", function () {
        let _this = $(this)
        let wid = _this.parent(".post-list-item").attr("type")
        let Prop= _this.parent(".post-list-item").attr("userProp")
        if (Prop == 1) {
            if (confirm('确定取消置顶吗？') == true) {
                updateWorks(wid)
            }
        } else {
            if (confirm('确定置顶吗？') == true) {
                updateWorks(wid)
            }
        }

    })
    $(".caogaoxiang_remove").on("click", function () {
        $(this).parents(".pinglun_xiangqing").remove();
    })

    //查看文章详情(跳转)
    $(".feed-box, #pinglun_xiangqing").on("click", ".link", function () {
        let id = $(this).parents(".post-list-item").attr("type")
        let type = $(this).parents(".post-list-item").attr("type_type")
        $.session.set('uid', id)
        if (type == 'svideo' || type == 'lvideo') {
            window.open("video.html?uid=" + id)
        } else {
            window.open("news.html?uid=" + id)
        }
    })
    //查看文章详情(跳转)
    $("#xiangqing_index").on("click", function () {
        let id = $(this).attr("type")
        let type = $(this).attr("type_type")
        $.session.set('uid', id)
        if (type == 'svideo' || type == 'lvideo') {
            window.open("video.html?uid=" + id)
        } else {
            window.open("news.html?uid=" + id)
        }
    })

    $(".redian, .carousel-inner").on('click', '.redian_1, .item', function () {
        let uid = $(this).attr('uid');
        let type = $(this).attr('type');
        $.session.set('uid', uid);
        if (type == 'svideo' || type == 'lvideo') {
            window.open("video.html?uid=" + uid)
        } else {
            window.open("news.html?uid=" + uid)
        }
    });


    //进入草稿箱(跳转)
    $(".feed-box").on("click", ".to_caogao", function () {
        let id = $(this).parents(".post-list-item").attr("type")
        let type = $(this).parents(".post-list-item").attr("type_type")
        $.session.set("caogao", JSON.stringify(user_caogao[id]))
        console.log(type)
        switch (type) {
            case "文章":
                window.location.href = "publish.html?type=wenzhang"
                break
            case "视频":
                window.location.href = "publish.html?type=shipin"
                break
            case "图文":
                window.location.href = "publish.html?type=tuwen"
                break
            case "微头条":
                window.location.href = "publish.html?type=weitoutiao"
                break

        }

    })


    // 头像
    /* 隐藏，显现效果 */
    $(".t_img").click(function () {
        $("#sbox").show("slow");
    });
    $("#hide").click(function () {
        $("#user_headimg").attr("src", userimg)
        $("#sbox").hide("slow");
    });
    $("#close").click(function () {
        $("#sbox").hide("slow");
    });

    //点击确认修改按钮更换头像
    $("#but").click(function () {
        let headImg = Return_videotpic().toString();
        set_upload_param_head(uploader_head_img, '', false);
        console.log(headImg);
        submit_head(headImg);
        $("#sbox").hide("slow");
    })

    //模态框
    var myModal_type;
    $('#myModal').modal('hide')
    $(".myModal").on('click', function () {
        myModal_type = $(this).attr("type");
        console.log(myModal_type)
        if (myModal_type == "mima") {
            $("#modal_text").hide()
            $("#modal_renzheng").hide()
            $("#modal_zhuce").show()
        } else if (myModal_type == "renzheng") {
            $("#modal_text").hide()
            $("#modal_zhuce").hide()
            $("#modal_renzheng").show()
        } else {
            $("#modal_zhuce").hide()
            $("#modal_renzheng").hide()
            $("#modal_text").show()
        }
        $('#myModal').modal('show');
        let text = $("." + myModal_type).text()
        $(".modal-text").val(text)

    })
    $('.btn-primary').on('click', function () {
        let type = myModal_type;
        let text = $(".modal-text").val();
        let pass = $("#login_password2").val();

        if (text || pass) {
            switch (type) {
                case "renzheng":
                    $(".renzheng").text(text);
                    submit_renzheng(text)
                    break;
                case "nicheng":
                    $(".xiangqing .nicheng").text(text);
                    submit_nicheng(text)
                    break;
                case "qianming":
                    $(".xiangqing .qianming").text(text);
                    submit_qianming(text)
                    break;
                case "mima":
                    let phone = $("#logon_phone").val()
                    let phoneCode = $("#yanzhengma_text1").val()
                    let password = $("#login_password2").val()
                    console.log(phone, phoneCode, password)
                    submit_pass(phone, phoneCode, password)
                    break;
            }
        }
        $('#myModal').modal('hide');
    })


    $('#myModal_mess').modal('hide')
    $("#user_message, #user_allmessage").on('click', ".myModal_mess", function () {
        $(".modal-body").text($(this).attr("text"))
        $('#myModal_mess').modal('show');
    })
    $('.btn-primary').on('click', function () {
        $(".modal-body").text("")
        $('#myModal_mess').modal('hide');
    })

})


//连接后端
//ajax区域
//查询
function getindex(user, type, pageNum, pageSize) {
    // 我的文章
    $.ajax({
        url: baseURL + '/webapi/works/searchUserAllPage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "user": user,
            // "type": type,
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            console.log(data);
            if (data.code == 1) {
                user_allwork = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })
    //我的关注
    $.ajax({
        url: baseURL + '/webapi/userFollow/searchUserFollowPage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "user": user,
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_attent = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })
    //我的粉丝
    $.ajax({
        url: baseURL + '/webapi/userFollow/searchUserfansPage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "user": user,
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_fans = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })
    //用户信息
    $.ajax({
        url: baseURL + '/webapi/user/searchUser',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "id": user,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_info = data.data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })


}

function getmessage(look, pageNum, pageSize) {
    //我的消息
    $.ajax({
        url: baseURL + '/webapi/userMessage/searchUserMessage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "look": look,
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_message = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })

}

function getcollect(pageNum, pageSize) {

    $.ajax({
        url: baseURL + '/webapi/works/searchUserWorkPage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_collect = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })

}

function getcomment(pageNum, pageSize) {
    //我的评论
    $.ajax({
        url: baseURL + '/webapi/works/searchUserCommentWorksPage',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "pageNum": pageNum,
            "pageSize": pageSize,
        },
        success: function (data) {
            if (data.code == 1 || data.code == -3000) {
                user_comment = data
            } else if (data.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(data.msg)
            }
        }
    })

}


//修改
function submit_renzheng(text) {
    $.ajax({
        url: baseURL + '/',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "name": text,
        },
        success: function (e) {
            if (e.code == 1) {
                user_data.name = text
                $.cookie('user_data', JSON.stringify(user_data), {expires: 7, path: '/'});
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }

        }
    })

}

function submit_nicheng(text) {
    $.ajax({
        url: baseURL + '/webapi/user/updateName',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "name": text,
        },
        success: function (e) {
            if (e.code == 1) {
                user_data.name = text
                $.cookie('user_data', JSON.stringify(user_data), {expires: 7, path: '/'});
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }

        }
    })

}

function submit_qianming(text) {
    $.ajax({
        url: baseURL + '/webapi/user/updateSignature',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "signature": text,
        },
        success: function (e) {
            if (e.code == 1) {
                user_data.signature = text
                $.cookie('user_data', JSON.stringify(user_data), {expires: 7, path: '/'});
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
        }
    })
}

function submit_pass(phone, phoneCode, password) {
    $.ajax({
        url: baseURL + '/webapi/user/resetPassword',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "phone": phone,
            "phoneCode": phoneCode,
            "newPassword": password,
        },
        success: function (e) {
            if (e.code == 1) {
                user_data.password = password
                $.cookie('user_data', JSON.stringify(user_data), {expires: 7, path: '/'});
                alert("修改成功，请重新登录")
                $.session.clear()
                window.location.href = "login.html"
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
        }
    })
}

function submit_head(headImg) {
    console.log(authorities, headImg)
    $.ajax({
        url: baseURL + '/webapi/user/updateHeadImg',
        type: 'post',
        dataType: 'json',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "headImg": headImg,
        },
        success: function (e) {
            console.log(e)
            if (e.code == 1) {
                user_data.headimg = headImg
                console.log(user_data);
                $.cookie('user_data', JSON.stringify(user_data), {expires: 7, path: '/'});
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
        }
    })
}

function remove_work(wid) {
    $.ajax({
        url: baseURL + '/webapi/works/delWorks',
        type: 'post',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "wid": wid,
        },
        success: function (e) {
            if (e.code == 1) {
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
            return e.code
        }
    })
}

function CollecWorks(wid) {
    $.ajax({
        url: baseURL + '/webapi/userWorks/addCollecWorks',
        type: 'post',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "works": wid,
        },
        success: function (e) {
            console.log(e)
            if (e.code == 1) {
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
            return e.code
        }
    })
}

function updateWorks(wid) {
    $.ajax({
        url: baseURL + '/webapi/works/updateBtWorksUserProp',
        type: 'post',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "works": wid,
        },
        success: function (e) {
            console.log(e)
            if (e.code == 1) {
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
            return e.code
        }
    })
}

function del_pinglun(id) {
    $.ajax({
        url: baseURL + '/webapi/works/comment/delWorksCommentById',
        type: 'post',
        async: false,//同步
        headers: {'authorities': authorities},
        data: {
            "id": id,
        },
        success: function (e) {
            console.log(e)
            if (e.code == 1) {
                alert(e.msg)
                location.reload()
            } else if (e.code == "401") {
                alert("账号在别处登录，请重新登录")
                window.location.href = "login.html"
            } else {
                alert(e.msg)
            }
            return e.code
        }
    })
}

function del_caogao(wid) {
    let data = user_caogao;
    console.log(user_caogao, wid)
    data.splice(wid, 1);
    window.localStorage.setItem("caogao", JSON.stringify(data))
    // location.reload()
    return "1"
}

//获取验证码
$("#yanzhengma_but1").on("click", function () {
    let phone = $("#logon_phone").val()
    if (timeClock == 30) {
        $.ajax({
            url: baseURL + '/login/api/web/getPhoneCode',
            type: 'post',
            dataType: 'json',
            // async: false,//同步
            headers: {'authorities': authorities},
            data: {
                "phone": phone,
            },
            success: function (e) {
                console.log(e)
                if (e.code == 1) {
                    sendCode()
                } else if (e.code == "401") {
                    alert("账号在别处登录，请重新登录")
                    window.location.href = "login.html"
                } else {
                    alert(e.msg)
                }
            }
        })
    }

})

//60秒倒计时
var timeClock = 30

function sendCode() {
    var timer_num = 30;
    $("#yanzhengma_but1").disabled = true;
    timeClock = setInterval(function () {
        timer_num--;
        $('#yanzhengma_but1').val(timer_num + " 秒");

        if (timer_num == 0) {
            clearInterval(timeClock);
            timeClock = 30
            $('#yanzhengma_but1').val("获取验证码");
            $("#yanzhengma_but1").disabled = false;
        }
    }, 1000)
}

//转换时间
function time(time) {
    let arr
    arr = time.split('T');
    return arr[0]
}

//认证身份
function authType(type) {
    switch (type) {
        case "media":
            return "媒体认证";
        case "government":
            return "机构认证";
        case "company":
            return "企业认证";
        case "personal":
            return "个人认证";

    }
}